<%@ page language="java" pageEncoding="UTF-8" contentType="text/html; charset=UTF-8" %>

$(function(){
	//表格加载
	var rootTable=$('#receiveStatusTable').datagrid({
	    url:'<c:url value="/receive/traceSourceData" />',
	    queryParams:getParams(),//提交参数
	    showHeader:false,
	    toolbar:'#receiveStatusToolbar',//表头工具栏
	   /* pagination:true,//显示分页  
	    pagePosition:'bottom',//分页栏出现位置
	    pageNumber:1,//初始页码
	    pageSize:10,//初始每页显示记录数量
*/	    singleSelect:true,
	    columns:[[
			{field:'issueName',align:'left',formatter: function(value,row,index){
				return "<font color='blue'>"+row.draftOrg+"</font> 发文：<a style='text-decoration: none;' title='"+value+"' href=\"javascript:openDonePage('"+row.issueId+"')\">"+value+"</a>";
			}}
	    ]],
		onLoadSuccess:function(data){
			if(data.total>0){
				rootTable.datagrid("expandRow",0);
				setTimeout(function(){
					rootTable.datagrid("resize");
				},1000);
			}
		},
	    view: detailview,
	    detailFormatter:function(index,row){
			return '<div style="width: 98%;margin: auto;"><table id="ddv-' + index + '" ></table></div>';
		},
		onExpandRow: function(parentIndex,parentRow){
			$('#ddv-'+parentIndex).datagrid({
				url:"<c:url value='/receive/receiveStatusDate'/>",
				queryParams:{"issueId":parentRow.issueId,"hidePassRound":"1"},//提交参数
				fitColumns:true,
				singleSelect:true,
				rownumbers:true,
				//loadMsg:'',
				height:'auto',
				columns:[[
					{field:'docReceiverOrgName',title:'接收单位',formatter: function(value,row,index){
						return row.docSendUuid?("<a style='text-decoration: none;' title='"+value+"' href=\"javascript:openDonePage('"+row.docSendUuid+"')\">"+value+"</a>"):value;
					}},
					{field:'docArrived',title:'接收情况',formatter: function(value,row,index){
						var docReceiveStat=row.docReceiveStat;
						if(value == 0){
		                    return "<font color='red'>未送达</font>";
		                } else if(value == 1 && docReceiveStat==0){
		                	return "已送达";
		                } else if(value == 1 && docReceiveStat==1){
		                	return "已签收"+(row.docReceiveInfo==""||row.docReceiveInfo=="null"||row.docReceiveInfo==null?"":"(回执信息: "+row.docReceiveInfo+")");
						} else if(value == 1 && docReceiveStat==2){
							return "<font color='red'>已拒收</font>"+(row.docReceiveInfo==""||row.docReceiveInfo=="null"||row.docReceiveInfo==null?"":"(回执信息: "+row.docReceiveInfo+")");
						}else if(value == 1 && docReceiveStat==3){
							return "<font color='red'>已收回</font>";
						}else{
							return "发送失败"==row.docReceiveAddress || ("null"==row.docReceiveAddress || null==row.docReceiveAddress) && (null==row.docReceiverId || 'null'==row.docReceiverId)?("<font color='red'>发送失败</font>"):row.docReceiveAddress;
						}
					}},
					{field:'docArriveTime',align:'center',title:'送达时间',formatter: function(value,row,index){
						var str="";
						if(value){
							str=dataFormatStr(new Date(value),"yyyy-MM-dd hh:mm:ss");
						}
						return str;
					}},
					{field:'docCheckinTime',align:'center',title:'办理时间',formatter: function(value,row,index){
						var str="";
						if(value){
							str=dataFormatStr(new Date(value),"yyyy-MM-dd hh:mm:ss");
						}
						return str;
					}}
				]],
				onResize:function(){
					rootTable.datagrid('fixDetailRowHeight',parentIndex).datagrid("resize");
				},
				onLoadSuccess:function(data){
					setTimeout(function(){
						rootTable.datagrid('fixDetailRowHeight',parentIndex).datagrid("resize");
					},1000);
					
				}
			});
		}
	});
});

//查询条件生成方法
function getParams(){
	var jsonObj=new Object();
	/*if($('input[name="formCategoryId"]').val()!=""){
		jsonObj.formCategoryId=$('input[name="formCategoryId"]').val();
	}*/
	jsonObj.issueId="<c:out value='${issueId}' />";
	return jsonObj;
}
function openDonePage(issueId){
	var url=_synergyContext+"/basic/donePage?issueId="+issueId+"&backType=close"; 
	var winFeatures = "height="+(window.screen.height-80)+"px,width="+(window.screen.width-20)+"px,toolbar=no,menubar=no,scrollbars=yes,resizable=no,location=no,status=no";
	window.open(url,'_blank',winFeatures);
}